// pages/crowdraising/iwantcrowd/iwantcrowd.js
var utils = require('../../../utils/util.js');
var WxParse = require('../../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isback: false,
    currentBut: 0,
    isHide: true //支付弹窗是否显示
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    const res = wx.getSystemInfoSync();
    that.setData({
      id: options.id,
      windowHeight: res.windowHeight - 44
    })
    that.crowdDetail();
  },
  crowdDetail: function(e) {
    var that = this;
    utils.http("/api/v1/Crowdgoods/goods_detail", {
      id: that.data.id
    }, function(res) {
      WxParse.wxParse('article', 'html', res.datas.goods_info.content, that, 5);
      res.datas.goods_info.number = 0;
      that.setData({
        data: res.datas
      })
    })
  },
  //加数量
  onPrevTap: function(e) {
    var that = this;
    var itemslist = that.data.data;
    var index = e.currentTarget.dataset.index;
    var num = e.currentTarget.dataset.number;
    itemslist.goods_info.number = itemslist.goods_info.number + 1;
    that.setData({
      data: itemslist
    })
  },
  //支付方式
  paymentTypeTap: function(e) {
    var id = e.currentTarget.dataset.id;
    var currentBut = id;
    this.setData({
      currentBut: currentBut,
      type: e.currentTarget.dataset.type
    })
  },
  //立即购买
  buyNowTap: function(e) {
    var id = e.currentTarget.dataset.id;
    var goodsid = e.currentTarget.dataset.goodsid;
    var image = e.currentTarget.dataset.image;
    var name = e.currentTarget.dataset.name;
    var subtitle = e.currentTarget.dataset.subtitle;
    var price = e.currentTarget.dataset.price;
    var num = e.currentTarget.dataset.num;
    wx.navigateTo({
      url: '../../crowconfirmorder/crowconfirmorder?id=' + id + "&goodsid=" + goodsid + "&num=" + num + "&name=" + name + "&subtitle=" + subtitle + "&price=" + price + "&image=" + image
    })
  },
  //去逛逛
  onGogoTap: function(e) {
    wx.navigateBack({
      delta: 1,
    })
  },
  //减数量
  onNextTap: function(e) {
    var that = this;
    var itemslist = that.data.data;
    var index = e.currentTarget.dataset.index;
    var ind = e.currentTarget.dataset.ind;
    if (itemslist.goods_info.number > 0) {
      itemslist.goods_info.number = itemslist.goods_info.number - 1;
      that.setData({
        data: itemslist
      })
    } else {
      utils.message("该宝贝宝贝不能减少哦~")
    }

  },
  //点击我要筹出现弹窗
  onBackColseTap: function(e) {
    var that = this;
    that.setData({
      isback: true
    })
  },
  //关闭我要筹
  onClosebackTap: function(e) {
    var that = this;
    that.setData({
      isback: false
    })
  },
  //关闭支付弹窗
  onColseTap: function(e) {
    this.setData({
      isHide: true
    })
  },
  //打开支付弹窗
  onOrderTap: function(e) {
    this.setData({
      isHide: false,
      isback: false
    })
  },
  //店铺单项选择 （选择自提）
  bindButTap: function(e) {
    console.log(e.currentTarget.dataset.current);
    var id = e.currentTarget.dataset.current;
    this.setData({
      currentBut: id
    })
  },
  onShareAppMessage: function() {
    return utils.share();
  }
})